home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / Animation Class Library / Examples / ACL-World / Sources / Sorting.cp < prev   
Encoding:
Text File  |  1994-09-02  |  4.0 KB  |  177 lines  |  [TEXT/MMCC]

  1.  
  2. /********************************************
  3.  **** ACL-World
  4.  ****
  5.  **** Controls.cp
  6.  ****
  7.  **** Created:      25 August 1994
  8.  **** Modified:     30 August 1994
  9.  **** Version:      0
  10.  **** Compatible:   C++, Mac System 7
  11.  ****
  12.  **** Description:    Sorting demo.
  13.  ****
  14.  *******************/
  15.  
  16. #include "ACL-World.h"
  17.  
  18. //*************************************
  19.  
  20.  
  21. static const short PICT_BACKGROUND     = 157;
  22. static const short PICT_MONSTER     = 156;
  23. static const short PICT_PERS         = 160;
  24.  
  25.  
  26.  
  27. //*************************************
  28.  
  29. #define    TEXTSTEP1    "\pSuppose that there are two objects on screen: a character and a bird. Should the bird be in front of the character..."
  30.  
  31. #define    TEXTSTEP2    "\pOr should the character be in front of the bird? All moveable objects of ACL have a sorting priority. Objects which have the higher priority are draw in front of others. At any time the user can change the priority of an object."                    
  32.  
  33.                     
  34. #define    TEXTSTEP3    "\pNow look at this background. How should be sorted objects? Objects which have the smaller vertical position should be drawed behind the others. ACL implements eight algorithms which allow automatic sorting."
  35.                     
  36.  
  37. #define    TEXTSTEP4    "\pIn this example an ACL algorithm may be installed to automatically sort the object using the vertical position. Click in the picture to move the charactere and examine the result of the automatic classing."
  38.         
  39.                          
  40.                     
  41. //*************************************
  42.  
  43. static AnimGfx    *background;
  44. static short    backwidth,backheight;
  45. static Anim        *anims[5];
  46.  
  47.  
  48. //*************************************
  49.  
  50. Boolean ACLWorld::sorting_advance(void)
  51. {
  52.     short     i;
  53.     Handle     ha;
  54.     Rect    rect;
  55.  
  56.     static short w,h;
  57.  
  58.  
  59.     step++;
  60.     
  61.     GetDItem(dialog,1,&i,&ha,&rect);
  62.     
  63.     switch(step)
  64.     {
  65.         case 1:
  66.         SetIText(ha,TEXTSTEP1);
  67.         animbase->setsortflags(ASORT_PRIORITY);
  68.         
  69.         anims[0] = animbase->createanim(PICT_PERS);        
  70.         anims[1] = animbase->createanim(PICT_MONSTER);
  71.         anims[0]->arrange_movehandlepoint(0,0,-1);
  72.         anims[1]->arrange_movehandlepoint(0,0,-1);
  73.         anims[0]->findmaxsize(&w,&h);
  74.         anims[0]->place((backwidth/2)-(w/2),((backheight/2)-(h/2))+h);
  75.         anims[1]->findmaxsize(&w,NULL);
  76.         anims[1]->place((backwidth/2)-(w/2),((backheight/2)-(h/2))+h);    
  77.         anims[1]->setpriority(10);    
  78.         return FALSE;
  79.  
  80.         case 2:
  81.         SetIText(ha,TEXTSTEP2);
  82.         anims[0]->setpriority(20);    
  83.         return FALSE;
  84.  
  85.         case 3:
  86.         SetIText(ha,TEXTSTEP3);
  87.         animbase->installbackground(background);
  88.         anims[2] = animbase->createanim(PICT_MONSTER);
  89.         anims[3] = animbase->createanim(PICT_MONSTER);
  90.         anims[4] = animbase->createanim(PICT_MONSTER);
  91.         anims[2]->arrange_movehandlepoint(0,0,-1);
  92.         anims[3]->arrange_movehandlepoint(0,0,-1);
  93.         anims[4]->arrange_movehandlepoint(0,0,-1);
  94.         anims[0]->findmaxsize(&w,&h);
  95.         anims[0]->arrange_moveframeoffsets(0, -(w/2), 0);
  96.         
  97.         animbase->setsortflags(ASORT_BOTTOMRIGHT);
  98.         anims[0]->place((backwidth/2)-(w/2),((backheight/2)-(h/2))+h+30);
  99.         anims[1]->place(60,145);
  100.         anims[2]->place(280,200);
  101.         anims[3]->place(60,198);
  102.         anims[4]->place(330,185);
  103.         
  104.         return FALSE;
  105.  
  106.         case 4:
  107.         SetIText(ha,TEXTSTEP4);
  108.         return FALSE;
  109.         
  110.     }
  111.     
  112.     
  113.     return TRUE;
  114. }
  115.  
  116.  
  117.  
  118. //*************************************
  119.  
  120. Boolean ACLWorld::do_sorting(void)
  121. {
  122.     Point p;
  123.     char  key;
  124.     short res;
  125.     Boolean done = FALSE;
  126.  
  127.     pleasewait(TRUE);
  128.  
  129.     animbase = new AnimBase();
  130.     
  131.     background = animbase->newgfx(PICT_BACKGROUND);
  132.     animbase->newgfx(PICT_PERS);
  133.     animbase->newgfx(PICT_MONSTER);
  134.  
  135.     backwidth = background->getwidth();
  136.     backheight = background->getheight();
  137.         
  138.     animbase->buildbuffer(460,217);
  139.     animbase->setbasex(17);
  140.     animbase->setbasey(8);
  141.  
  142.  
  143.     pleasewait(FALSE);
  144.  
  145.     step = 0;
  146.     openbasedialog();
  147.     SetWTitle(dialog,"\pSorting");
  148.     sorting_advance();
  149.  
  150.     
  151.     for(;;)
  152.     {
  153.         res = processbasedialog(key,p);
  154.         
  155.         if         (res==DO_QUIT) {done=TRUE; break;}
  156.         else if (res==DO_MENU) break;
  157.         else if (res==DO_CONTINUE && sorting_advance()) break;
  158.         else if (res==DO_MOUSECLICK && step==4)
  159.         {
  160.             if (p.h<460 && p.v<217 && p.h>=0 && p.v>=0)
  161.             {
  162.                 if (p.v<140) p.v=140;            
  163.                 anims[0]->place(p.h,p.v);
  164.             }
  165.         }
  166.         
  167.     }
  168.     
  169.     closebasedialog();
  170.     
  171.     delete animbase;
  172.  
  173.     return done;
  174. }
  175.  
  176. //*************************************
  177.